<template>
	<view class="box">
		<view class="login" v-if="usermsg.length == 0">
			<button type="primary" @click="login">点击登陆</button>
		</view>
		<view class="userinfo" v-else>
			<image :src="usermsg.avatarUrl"></image>
			<view>欢迎 {{usermsg.nickName}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				usermsg: []
			}
		},
		methods: {
			login() {
				uni.getUserProfile({
					desc: '展示登陆信息使用',
					success: res => {
						this.usermsg = res.userInfo
						console.log(this.usermsg)
						uni.showToast({
							title: '登陆成功',
							icon:'none'
						})
					},
					fail: err => {
						uni.showToast({
							title: '未能获取到用户信息',
							icon:'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background-color: #F8F8F8;

		.box {
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;

			.login {
				button {
					width: 220rpx;
					height: 80rpx;
					line-height: 80rpx;
				}
			}

			.userinfo {
				text-align: center;
				width: 130rpx;
				height: 130rpx;

				image {
					width: 120rpx;
					height: 120rpx;
					border: 3rpx solid #e1e1e1;
					border-radius: 50%;
				}

				view {
					text-align: center;
				}
			}
		}
	}
</style>
